<!--
 * @Descripttion: 
 * @version: 
 * @Author: wl
 * @Date: 2020-05-13 13:27:23
 * @LastEditors: wl
 * @LastEditTime: 2020-06-24 19:44:10
--> 
<template>
  <div class="group">
    <page :headerShow="headerShow" :footShow="footShow">
      <div slot="aside">
        <el-tabs v-model="activeTabName" type="card">
          <el-tab-pane label="组织机构" name="first">
            <outUnitTreeEdit
              @click="handleOutUnitClick"
              @delete="handleDelete"
              @add="handleAdd"
              :width="'100%'"
              ref="outUnitTree"
            ></outUnitTreeEdit>
          </el-tab-pane>
        </el-tabs>
      </div>

      <!--表格内容栏-->
      <div slot="content" class="contentH">
        <groudEid
          :dataForm="dataForm"
          :operation="operation"
          :showEid="showEid"
          @clickCancel="handleQuery"
        ></groudEid>
      </div>
    </page>
  </div>
</template>

<script>
import viewPage from "./comments/deptView.vue";
import editPage from "./comments/deptAdd.vue";
import outUnitTreeEdit from "./comments/OutUnitTreeEdit";

import groudEid from "./comments/groudEid";

export default {
  components: {
    editPage,
    outUnitTreeEdit,
    viewPage,
    groudEid
  },

  data() {
    return {
      showEid: true,
      operation: 0,
      editVisible: false,
      dataForm: {
        imgs: [],
        photos: []
      },
      activeTabName: "first",
      headerShow: false,
      footShow: false,
      accessoryAsideShow: true,
      draggable: true
    };
  },
  methods: {
    /* 点击临时学员 */
    handleOutUnitClick: function (data, node, base) {
      this.showEid = false;
      this.dataForm = Object.assign({}, data);

      if (!data.imgs) {
        this.dataForm.imgs = [];
      }
      if (!data.photos) {
        this.dataForm.photos = [];
      }
      this.dataForm.children = [];
      this.dataForm.show = true;
    },
    /* 新增临时学员 */
    handleAdd: function (data) {
      this.showEid = true;
      var fromList = {
        imgs: [],
        photo: [],
        photos: [],
        phone: "",
        address: "",
        longitude: "",
        latitude: "",
        des: "",
        organs: "",
        type: "",
        encoded: "",
        zooms: ""
      };
      this.dataForm = Object.assign(fromList, data);
      (this.dataForm.CODES = []), (this.dataForm.children = []);
      this.dataForm.show = true;
    },
    /* 删除临时学员 */
    handleDelete: function (data) {
      this.$confirm("确认删除选中记录吗？", "提示", {
        type: "warning"
      })
        .then(() => {
          let params = {
            tbn: "authority_group",
            where: {
              _id: data._id
            }
          };

          var aaa = JSON.stringify(params);
          this.$api.menu.batchDelete(aaa).then((res) => {
            if (res.code == 0) {
              this.handleQuery();
              this.$message({ message: "删除成功", type: "success" });
            } else {
              this.$message({
                message: "操作失败, " + res.msg,
                type: "error"
              });
            }
          });
        })
        .catch(() => {
          this.$message({ message: "已取消删除", type: "success" });
        });
    },
    handleQuery: function () {
      this.$refs.outUnitTree.handleQuery();
    }
  }
};
</script>

<style lang="scss" scoped>
.group {
  width: 100%;
  height: 314px;
  .aside {
    width: 500px;
    height: 750px;
    overflow: auto;
  }
}
.contentNull {
  margin-top: 100px;
}
</style>